package com.young.ysepay.service.impl;

import com.alibaba.fastjson.JSON;
import com.young.ysepay.beans.YsPayOrderBean;
import com.young.ysepay.dto.YsPayDTO;
import com.young.ysepay.service.YsBusinessPramService;
import com.young.ysepay.service.YsService;
import com.young.ysepay.utils.DateFormatHelper;
import com.young.ysepay.utils.Https;
import com.young.ysepay.utils.ReturnUtils;
import com.young.ysepay.utils.SignUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;



@Service
public class YsServiceImpl implements YsService {
    @Autowired
    private YsBusinessPramService ysBusinessPramService;

    private static Logger log = LoggerFactory.getLogger(YsServiceImpl.class);

    /**
     * 订单支付
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, Object> orderPay(YsPayOrderBean m) {
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, String> param = new HashMap<String, String>();
        param.put("partner_id",ysPayDTO.getPARTNER_ID());  //222
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM()); ///5
        param.put("notify_url", ysPayDTO.getNOTIFY_URL());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());//333
        param.put("method", ysPayDTO.getMETHOD());   ///111
        param.put("extra_common_param", m.getExtra_common_param());

        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("subject", m.getSubject());
        biz_contentMap.put("total_amount", m.getTotal_amount() + "");
        biz_contentMap.put("seller_name", ysPayDTO.getSELLER_NAME());
        biz_contentMap.put("seller_id", ysPayDTO.getPARTNER_ID());
        biz_contentMap.put("timeout_express", ysPayDTO.getTIMEOUT_EXPRESS());
        biz_contentMap.put("business_code", ysPayDTO.getBUSINESS_CODE());
        biz_contentMap.put("spbill_create_ip", m.getSpbill_create_ip());
        biz_contentMap.put("bank_type", m.getBank_type());
/*-----------------------新增参数-----------------------------------*/
        biz_contentMap.put("shopdate", m.getShopdate());
        param.put("biz_content", JSON.toJSONString(biz_contentMap));
        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_h5_pay_response");
            Map<String, Object> ysepay_online_h5_pay_response = (Map) JSON.parseObject(obj.toString());
            ysepay_online_h5_pay_response.put("sign", resultMap.get("sign"));

            boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), obj.toString(), "utf-8");
            resultMap.putAll(ysepay_online_h5_pay_response);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    /**
     * 订单退款接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, Object> orderRefund(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("method", "ysepay.online.trade.refund");

        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("out_request_no", m.getOut_request_no());
        biz_contentMap.put("refund_reason", m.getRefund_reason());
        biz_contentMap.put("refund_amount", m.getRefund_amount() + "");
        biz_contentMap.put("trade_no", m.getTrade_no());

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        //签名
        Map<String, String> sPara = buildRequestPara(param);

        try {
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_trade_refund_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, String> ysepay_online_trade_refund_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_online_trade_refund_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_online_trade_refund_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                resultMap.putAll(ysepay_online_trade_refund_response);
            }
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }


    /**
     * 退款查询接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, Object> orderRefundSelect(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("method", "ysepay.online.trade.refund.query");

        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("out_request_no", m.getOut_request_no());
        biz_contentMap.put("trade_no", m.getTrade_no());
        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        //签名
        Map<String, String> sPara = buildRequestPara(param);

        try {
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_trade_refund_query_response");
            Map<String, Object> ysepay_online_trade_refund_query_response = (Map) JSON.parseObject(obj.toString());
            //ysepay_online_trade_refund_query_response.put("sign", resultMap.get("sign"));

            int ss = returnString.toString().indexOf("ysepay_online_trade_refund_query_response");
            String str = returnString.substring(ss);
            str = str.replace("ysepay_online_trade_refund_query_response", "");
            str = str.substring(2, str.length() - 1);

            boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
            resultMap.putAll(ysepay_online_trade_refund_query_response);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    /**
     * 银盛支付提现接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, String> ysePayWithdraw(YsPayOrderBean m) {
        StringBuilder sb = new StringBuilder();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> resultMap = new HashMap<String, String>();
        try {
            Map<String, String> param = new HashMap<String, String>();
            /*System.out.println("partner_id=" + ysepayConfig.PARTNER_ID_DF);*/
            System.out.println("sign_type=" + ysPayDTO.getSIGN_ALGORITHM());
            System.out.println("charset=" + ysPayDTO.getDEFAULT_CHARSET());
            System.out.println("version=" + ysPayDTO.getVERSION());
            /*param.put("partner_id", ysepayConfig.PARTNER_ID_DF);*/
            param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
            param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
            param.put("version", ysPayDTO.getVERSION());
            param.put("timestamp", DateFormatHelper.getNowTimeStr());
            //普通
            //param.put("method", "ysepay.df.single.normal.accept");
            //加急
            param.put("method", "ysepay.df.single.quick.accept");
            /*param.put("notify_url", ysepayConfig.NOTIFY_DF_URL);
            System.out.println("notify_url=" + ysepayConfig.NOTIFY_DF_URL);*/
            Map<String, String> biz_contentMap = new HashMap<String, String>();
            biz_contentMap.put("out_trade_no", m.getOut_trade_no());
            //1.当商户号为空时，默认将partner_id,作为商户号 2.如果提现的商户号和合作商户号不一致则需要检查机构信息
//			biz_contentMap.put("merchant_usercode", m.getMerchant_usercode());
            biz_contentMap.put("shopdate", m.getShopdate());
            //业务代码 生产 2010022   测试：01000018
            biz_contentMap.put("business_code", "2010022");
            biz_contentMap.put("currency", "CNY");
            biz_contentMap.put("total_amount", m.getTotal_amount() + "");
            biz_contentMap.put("subject", m.getSubject());
            //银行名称，为了保证代付交易成功，银行名称最好具体到分行
            biz_contentMap.put("bank_name", m.getBank_name());
            //开户行所在城市
            biz_contentMap.put("bank_city", m.getBank_city());
            //银行帐号，注：当bank_account_type为对公账户时，该属性字段长度可以为String(1,32)
            biz_contentMap.put("bank_account_no", m.getBank_account_no());
            //银行帐号用户名
            biz_contentMap.put("bank_account_name", m.getBank_account_name());
            //收款方银行账户类型，此处必填
            //corporate :对公账户;personal:对私账户
            biz_contentMap.put("bank_account_type", m.getBank_account_type());
            //支持卡类型，此处必填 	debit:借记卡;credit:信用卡 unit:单位结算卡
            biz_contentMap.put("bank_card_type", m.getBank_card_type());

            param.put("biz_content", JSON.toJSONString(biz_contentMap));
            System.out.println("biz_content=" + JSON.toJSONString(biz_contentMap));
            //签名
            Map<String, String> sPara = buildRequestParaDF(param);
            String responseStr = JSON.toJSONString(sPara);
            System.out.println("请求参数含有签名=" + responseStr);
            sb.append("\r\n 请求参数含有签名 = " + responseStr);
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            System.out.println("银盛返回数据=" + returnString);
            sb.append("\r\n 返回数据 = " + returnString);
            System.out.println("返回数据 = " + returnString);
            resultMap = (Map) JSON.parseObject(returnString);
            Object obj = resultMap.get("ysepay_df_single_quick_accept_response");
            if (obj != null) {
                Map<String, String> ysepay_df_single_normal_accept_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_df_single_quick_accept_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_df_single_quick_accept_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_df_single_normal_accept_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_df_single_normal_accept_response);
                if (verifyResult) {
                    resultMap.put("verifyResult", "0");
                } else {
                    resultMap.put("verifyResult", "1");
                }
            }
        } catch (IOException e) {
            sb.append("\r\n 错误 = " + e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            sb.append("\r\n 错误 = " + e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            sb.append("\r\n 错误 " + e.getMessage());
        } finally {
            //payLog.info(sb.toString());
            return resultMap;
        }
    }


    /**
     * 银盛支付代付查询（提现查询）
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, String> ysePayDfQuery(YsPayOrderBean m) {
        Map<String, String> resultMap = new HashMap<String, String>();
        return resultMap;
    }

    /**
     * 银盛支付普通子商户提现付接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, String> ysePayMerchantWithdraw(YsPayOrderBean m) {
        StringBuilder sb = new StringBuilder();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> resultMap = new HashMap<String, String>();
        try {
            Map<String, String> param = new HashMap<String, String>();
            System.out.println("partner_id=" + ysPayDTO.getPARTNER_ID());
            System.out.println("sign_type=" + ysPayDTO.getSIGN_ALGORITHM());
            System.out.println("charset=" + ysPayDTO.getDEFAULT_CHARSET());
            System.out.println("version=" + ysPayDTO.getVERSION());
            param.put("partner_id", ysPayDTO.getPARTNER_ID());
            param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
            param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
            param.put("version", ysPayDTO.getVERSION());
            param.put("timestamp", DateFormatHelper.getNowTimeStr());
            param.put("method", "ysepay.merchant.withdraw.quick.accept");
            param.put("notify_url", ysPayDTO.getNOTIFY_TX_URL());
            System.out.println("notify_url=" + ysPayDTO.getNOTIFY_TX_URL());
            Map<String, String> biz_contentMap = new HashMap<String, String>();
            biz_contentMap.put("out_trade_no", m.getOut_trade_no());
            //1.当商户号为空时，默认将partner_id,作为商户号 2.如果提现的商户号和合作商户号不一致则需要检查机构信息
            biz_contentMap.put("merchant_usercode", m.getMerchant_usercode());
            biz_contentMap.put("shopdate", m.getShopdate());
            biz_contentMap.put("currency", "CNY");
            biz_contentMap.put("total_amount", m.getTotal_amount() + "");
            biz_contentMap.put("subject", m.getSubject());
            //银行帐号，注：当bank_account_type为对公账户时，该属性字段长度可以为String(1,32)
            biz_contentMap.put("bank_account_no", m.getBank_account_no());

            param.put("biz_content", JSON.toJSONString(biz_contentMap));
            System.out.println("biz_content=" + JSON.toJSONString(biz_contentMap));
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            String responseStr = JSON.toJSONString(sPara);
            System.out.println("请求参数含有签名=" + responseStr);
            sb.append("\r\n 请求参数含有签名 = " + responseStr);
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            System.out.println("银盛返回数据=" + returnString);
            sb.append("\r\n 返回数据 = " + returnString);
            System.out.println("返回数据 = " + returnString);
            resultMap = (Map) JSON.parseObject(returnString);
            Object obj = resultMap.get("ysepay_merchant_withdraw_quick_accept_response");
            if (obj != null) {
                Map<String, String> ysepay_merchant_withdraw_quick_accept_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_merchant_withdraw_quick_accept_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_withdraw_quick_accept_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_merchant_withdraw_quick_accept_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_merchant_withdraw_quick_accept_response);
                if (verifyResult) {
                    resultMap.put("verifyResult", "0");
                } else {
                    resultMap.put("verifyResult", "1");
                }
            }
        } catch (IOException e) {
            sb.append("\r\n 错误 = " + e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            sb.append("\r\n 错误 = " + e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            sb.append("\r\n 错误 " + e.getMessage());
        } finally {
            //payLog.info(sb.toString());
            return resultMap;
        }
    }

    /**
     * 银盛支付普通子商户提现查询（提现查询）
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, String> ysePayMerchantQuery(YsPayOrderBean m) {
        Map<String, String> resultMap = new HashMap<String, String>();

        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        /*param.put("partner_id", ysepayConfig.PARTNER_ID_DF);*/
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("method", "ysepay.merchant.withdraw.quick.query");

        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("shopdate", m.getShopdate());

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        //签名
        Map<String, String> sPara = buildRequestParaDF(param);

        try {
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_merchant_withdraw_quick_query_response");
            if (obj != null) {
                Map<String, String> ysepay_merchant_withdraw_quick_query_response = (Map) JSON.parseObject(obj.toString());
                //boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(),ysepay_df_single_query_response.toString(),"utf-8");
                int ss = returnString.toString().indexOf("ysepay_merchant_withdraw_quick_query_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_withdraw_quick_query_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_merchant_withdraw_quick_query_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_merchant_withdraw_quick_query_response);
                if (verifyResult) {
                    resultMap.put("verifyResult", "0");
                } else {
                    resultMap.put("verifyResult", "1");
                }

            }
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    /**
     * 获取证书路径并且签名
     *
     * @param sParaTemp
     * @return
     */
    @Override
        public  Map<String, String> buildRequestPara(Map<String, String> sParaTemp) {

        //除去数组中的空值和签名参数
        Map<String, String> sPara = SignUtils.paraFilter(sParaTemp);
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //私钥证书路径
        String partnerCert = ysPayDTO.getPATH_PARTER_PKCS12();

        //读取证书
        InputStream pfxCertFileInputStream = null;//servletContext.getResourceAsStream(partnerCert);

        String mysign = "";
        try {
            pfxCertFileInputStream = new ClassPathResource(partnerCert).getInputStream();//加载本地的证书进行https加密传输
            //遍历以及根据重新排序

			/*
			构造静态配置变量（银盛支付配置参数）
			 */
            /*if (SignUtils.ysepayConfig == null) {
                new SignUtils(ysepayConfig);
            }*/
            String signContent = SignUtils.getSignContent(sPara);
            mysign = SignUtils.rsaSign1(signContent, sParaTemp.get("charset"), pfxCertFileInputStream,ysPayDTO);

        } catch (Exception e) {
            throw new RuntimeException("签名失败，请检查证书文件是否存在，密码是否正确");
        }

        sPara.put("sign", mysign);

        return sPara;
    }

    /**
     * 获取证书路径并且签名
     * @param sParaTemp
     * @return
     */
    public Map<String, String> buildRequestParaDF(Map<String, String> sParaTemp) {
        System.out.println("buildRequestParaDF==========");
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //除去数组中的空值和签名参数
        Map<String, String> sPara = SignUtils.paraFilter(sParaTemp);
        System.out.println("buildRequestParaDF====sPara======");
        //私钥证书路径
        String partnerCert = ysPayDTO.getPATH_PARTER_PKCS12_DF();
        System.out.println("partnerCert===" + partnerCert);
        //读取证书
        InputStream pfxCertFileInputStream = null;//servletContext.getResourceAsStream(partnerCert);
        /*
			构造静态配置变量（银盛支付配置参数）
	    */
        /*if (SignUtils.ysepayConfig == null) {
            new SignUtils(ysepayConfig);
        }*/

        String mysign = "";
        try {
            System.out.println("buildRequestParaDF==========try");
            pfxCertFileInputStream = new ClassPathResource(partnerCert).getInputStream();//加载本地的证书进行https加密传输
            //遍历以及根据重新排序
            String signContent = SignUtils.getSignContent(sPara);

            mysign = SignUtils.rsaSign2(signContent, sParaTemp.get("charset"), pfxCertFileInputStream,ysPayDTO);

        } catch (Exception e) {
            System.out.println("签名失败，请检查证书文件是否存在，密码是否正确");
            throw new RuntimeException("签名失败，请检查证书文件是否存在，密码是否正确");
        }

        sPara.put("sign", mysign);

        return sPara;
    }

    /**
     * API验证签名工具，把签名值，请求字符编码，返回结果(json body)传递过来进行验证签名 公钥验证签名
     * 用于验证银盛同步响应回来的参数
     * @param sign
     * @param responseBody
     * @param charset
     * @return
     * @see
     */
    @Override
    public boolean verifyJsonSign(String sign, String responseBody, String charset) {
//		ServletContext servletContext = request.getServletContext();
        InputStream publicCertFileInputStream = null;//servletContext.getResourceAsStream(ysepayConfig.PATH_YSEPAY_PUBLIC_CERT);
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();

        boolean isSign = false;
        try {
            publicCertFileInputStream = new ClassPathResource(ysPayDTO.getPATH_YSEPAY_PUBLIC_CERT()).getInputStream();//加载本地的证书进行https加密传输
            isSign = SignUtils.rsaCheckContent1(publicCertFileInputStream, responseBody, sign, charset,ysPayDTO);
        } catch (Exception e) {
            throw new RuntimeException("验证签名失败，请检查银盛公钥证书文件是否存在");
        }
        return isSign;
    }

    @Override
    public Map<String, String> ysePayQuery(YsPayOrderBean m) {
        Map<String, String> resultMap = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        LocalDateTime localDateTime = LocalDateTime.now();
        String timestamp = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        param.put("timestamp", timestamp);
        param.put("method", "ysepay.online.trade.query");
        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("shopdate", m.getShopdate());
        param.put("biz_content", JSON.toJSONString(biz_contentMap));
        //签名
        Map<String, String> sPara = buildRequestPara(param);
        try {
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_SEARCH(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_trade_query_response");
            if (obj != null) {
                Map<String, String> ysepay_online_trade_query_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_online_trade_query_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_online_trade_query_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_trade_query_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_online_trade_query_response);
                if (verifyResult) {
                    resultMap.put("verifyResult", "0");
                } else {
                    resultMap.put("verifyResult", "1");
                }

            }
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }


    }

    @Override
    public Map<String, String> ysePayCancle(YsPayOrderBean m) {
        Map<String, String> resultMap = new HashMap<String, String>();
        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("version", ysPayDTO.getVERSION());
        LocalDateTime localDateTime = LocalDateTime.now();
        String timestamp = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        param.put("timestamp", timestamp);
        param.put("method", "ysepay.online.trade.close");
        Map<String, String> biz_contentMap = new HashMap<String, String>();
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("shopdate", m.getShopdate());
        param.put("biz_content", JSON.toJSONString(biz_contentMap));
        //签名
        Map<String, String> sPara = buildRequestPara(param);
        try {
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_trade_close_response");
            if (obj != null) {
                Map<String, String> ysepay_online_close_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_online_trade_close_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_online_trade_close_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_close_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_online_close_response);
                if (verifyResult) {
                    resultMap.put("verifyResult", "0");
                } else {
                    resultMap.put("verifyResult", "1");
                }

            }
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }

    }


    /**
     * 银盛支付分账接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, Object> ysePayDivision(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        //分账登记
        param.put("method", "ysepay.single.division.online.accept");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("notify_url", ysPayDTO.getNOTIFY_FZ_URL());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        //商户批次号,格式：(S|F)+15位唯一流水，建议格式：S+YYYYMMDD+XXXXXXX.F表示代付，S表示代收。
        //单笔交易可空，批量交易时必填， 具体批次号以真正交易时的信息为准
        biz_contentMap.put("out_batch_no", m.getOut_batch_no());
        //原订单号
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        //主商户号（原交易收款方）
        biz_contentMap.put("payee_usercode", ysPayDTO.getPARTNER_ID());
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        biz_contentMap.put("total_amount", m.getTotal_amount());
        //是否重新分账Y：是，N：否    N  暂不支持重新分账
        biz_contentMap.put("is_again_division", "N");
        //分账模式01 ：比例，02：金额
        biz_contentMap.put("division_mode", "02");
        //原订单是否参与分账01：是，02否
        boolean divideFlag = m.getDivideFlag();
        if (divideFlag) {
            biz_contentMap.put("is_divistion", "01");
            biz_contentMap.put("div_list", m.getDivList());
        } else {
            biz_contentMap.put("is_divistion", "02");
        }
//		List<Map<String, String>> divList = new ArrayList<Map<String, String>>();
        //组装分账明细数据
//		Map<String, String> div_list = new HashMap<String, String>();
//		//分账商户号     注册的子商户号 也可以是主商户号
//		div_list.put("division_mer_usercode",m.getDivision_mer_usercode());
//		//分账比例
////		div_list.put("div_ratio",m.getDiv_ratio());
//		//分账金额    可空
//		div_list.put("div_amount",m.getDiv_amount());
//		//是否收取手续费（01：是，02否）
//		div_list.put("is_chargeFee","02"/*m.getIs_chargeFee()*/);
        //分账明细,包含merc_id, div_amount, div_ratio, is_chargeFee等4个属性
        //"div_list":[{"division_mer_usercode":"js_test","div_ratio":"0.006","is_chargeFee":"01"}]}
//		divList.add(div_list);


        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            //pushyslog.info("银盛支付分账接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            //pushyslog.info("银盛支付分账接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_single_division_online_accept_response");
            if (obj != null) {
                Map<String, String> ysepay_single_division_online_accept_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_single_division_online_accept_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_single_division_online_accept_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_single_division_online_accept_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_single_division_online_accept_response);

                //pushyslog.info("银盛支付分账查询接口验签："+verifyResult);
                resultMap.putAll(ysepay_single_division_online_accept_response);
                resultMap.put("verifyResult", verifyResult);
            }
            return resultMap;
        } catch (IOException e) {
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }


    /**
     * 分账查询接口
     *
     * @param orderPayNo 订单号
     * @return
     */
    @Override
    public Map<String, Object> ysePayDivisionQuery(String orderPayNo) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        //pushyslog.info("银盛支付分账查询订单支付单号："+orderPayNo);
        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //分账查询
        param.put("method", "ysepay.single.division.online.query");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        //原订单号
        biz_contentMap.put("out_trade_no", orderPayNo);
        //主商户号（原交易收款方）
        biz_contentMap.put("src_usercode", ysPayDTO.getPARTNER_ID());

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            ////pushyslog.info("银盛支付分账查询接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            ////pushyslog.info("银盛支付分账查询接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_single_division_online_query_response");
            if (obj != null) {
                Map<String, String> ysepay_single_division_online_query_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_single_division_online_query_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_single_division_online_query_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_single_division_online_query_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_single_division_online_query_response);

                ////pushyslog.info("银盛支付分账查询接口验签："+verifyResult);
                resultMap.putAll(ysepay_single_division_online_query_response);
                resultMap.put("verifyResult", verifyResult);
            }

            return resultMap;
        } catch (IOException e) {
            ////pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            ////pushyslog.info("\r\n 银盛支付分账接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            ////pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }


    /**
     * 获取对账单下载地址接口
     *
     * @param time
     * @return bill_download_url    账单下载地址链接，获取连接后30秒后未下载，链接地址失效。
     */
    @Override
    public Map<String, Object> ysePayDownloadUrl(String time) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        //pushyslog.info("\r\n 银盛支付对账单下载地址接口,对账单时间："+time);
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        //分账查询
        param.put("method", "ysepay.online.bill.downloadurl.get");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        //会计日期：日账单格式为yyyy-MM-dd
        biz_contentMap.put("account_date", time);

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            //pushyslog.info("\r\n 银盛支付对账单下载地址接口,参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            //pushyslog.info("\r\n 银盛支付对账单下载地址接口,返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_online_bill_downloadurl_get_response");
            if (obj != null) {
                Map<String, String> ysepay_online_bill_downloadurl_get_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_online_bill_downloadurl_get_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_online_bill_downloadurl_get_response", "");
                str = str.substring(2, str.length() - 1);
                boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_bill_downloadurl_get_response.put("sign", resultMap.get("sign").toString());
                resultMap.putAll(ysepay_online_bill_downloadurl_get_response);

                //pushyslog.info("银盛支付分账查询接口验签："+verifyResult);
                resultMap.putAll(ysepay_online_bill_downloadurl_get_response);
                resultMap.put("verifyResult", verifyResult);
            }
            return resultMap;
        } catch (IOException e) {
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            //pushyslog.info("\r\n 银盛支付分账接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }

    /**
     * 银盛实名认证接口
     *
     * @param m
     * @return
     */
    @Override
    public Map<String, Object> ysCheckBank(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        //payLog.info("银盛支付实名认证接口调用开始======================");
       YsPayDTO ysPayDTO= ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        //实名认证
        param.put("method", "ysepay.authenticate.four.key.element");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        //原订单号
        biz_contentMap.put("out_trade_no", m.getOut_trade_no());
        //商户日期(该参数做交易与查询时需要一致) 该日期需在当日的前后一天时间范围之内
        biz_contentMap.put("shopdate", m.getShopdate());
        //实名认证姓名
        biz_contentMap.put("bank_account_name", m.getBank_account_name());
        //银行帐号，支持对公对私
        biz_contentMap.put("bank_account_no", m.getBank_account_no());
        //银行预留手机号码，填写为四要素验证，不填写为三要素验证
        biz_contentMap.put("bank_mobile", m.getBank_mobile());
        //证件号码，目前只支持身份证
        biz_contentMap.put("id_card", m.getId_card());

        biz_contentMap.put("div_list", m.getDivList());

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            //payLog.info("银盛支付实名认证接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            //payLog.info("银盛支付实名认证接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_authenticate_four_key_element_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_online_h5_pay_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_authenticate_four_key_element_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_authenticate_four_key_element_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_h5_pay_response.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_online_h5_pay_response);
            }

            ////payLog.info("银盛支付实名认证接口验签："+verifyResult);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            ////payLog.info("\r\n 银盛支付实名认证接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            //payLog.info("\r\n 银盛支付实名认证接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            //payLog.info("\r\n 银盛支付实名认证接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }

    /**
     * 银盛商户余额查询接口
     *
     * @param paramMap
     * @return
     */
    @Override
    public Map<String, Object> ysBalanceQuery(Map<String,Object> paramMap) {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        System.out.println("银盛商户余额查询接口调用开始======================");
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Object temp = paramMap.get("biz_content");
        String bizContent = temp != null ? temp.toString(): null;

        Map<String, String> param = new HashMap<String, String>();
        //银盛商户余额查询接口
        param.put("method", "ysepay.merchant.balance.query");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        //Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        //查询的商户号
        // biz_contentMap.put("merchant_usercode", paramMap.get);

        param.put("biz_content", bizContent);

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            //payLog.info("银盛商户余额接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            //payLog.info("银盛商户余额接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_merchant_balance_query_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_merchant_balance_query_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_merchant_balance_query_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_balance_query_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_merchant_balance_query_response.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_merchant_balance_query_response);
            }

            //payLog.info("银盛商户余额接口验签："+verifyResult);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            //payLog.info("\r\n 银盛商户余额接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            //payLog.info("\r\n 银盛商户余额接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            //payLog.info("\r\n 银盛商户余额接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }


    @Override
    public Map<String, Object> yseUpToken() {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        //pushyslog.info("银盛获取上传图片token开始======");
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Map<String, String> param = new HashMap<String, String>();
        //分账查询
        param.put("method", "ysepay.merchant.register.token.get");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());
        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            //pushyslog.info("获取上传图片token接口,参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_IMAGE_TOKEN_URL(), sPara);
            //pushyslog.info("获取上传图片token接口,返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_merchant_register_token_get_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_merchant_register_token_get_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_merchant_register_token_get_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_register_token_get_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_merchant_register_token_get_response.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_merchant_register_token_get_response);
                resultMap.put("verifyResult", verifyResult);
            }
            return resultMap;
        }  catch (Exception e) {
            log.error("获取token失败：{}",e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
            ////pushyslog.info("获取上传图片token错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> ysRegistStore(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        ////payLog.info("商户报备注册======================");
        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //实名认证
        param.put("method", "ysepay.merchant.register.accept");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());
        param.put("notify_url", ysPayDTO.getNOTIFY_REGIST_URL());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        biz_contentMap.put("merchant_no", m.getMer_outside_custid());
        biz_contentMap.put("cust_type", m.getCust_type());
        biz_contentMap.put("token", m.getToken());
        biz_contentMap.put("another_name", m.getAnother_name());
        biz_contentMap.put("cust_name", m.getCust_name());
        biz_contentMap.put("industry", m.getIndustry());
        biz_contentMap.put("province", m.getProvince());
        biz_contentMap.put("city", m.getCity());
        biz_contentMap.put("company_addr", m.getCompany_addr());
        if (!"O".equals(m.getCust_type())) {
            biz_contentMap.put("legal_name", m.getLegal_name());
            biz_contentMap.put("bus_license", m.getBus_license());
            biz_contentMap.put("bus_license_expire", m.getBus_license_expire());
        }
        biz_contentMap.put("legal_cert_expire", m.getLegal_cert_no_time());
        biz_contentMap.put("legal_tel", m.getLegal_tel());
        biz_contentMap.put("legal_cert_type", m.getLegal_cert_type());
        biz_contentMap.put("legal_cert_no", m.getLegal_cert_no());
        biz_contentMap.put("settle_type", m.getSettle_type());
        biz_contentMap.put("bank_account_no", m.getBank_account_no());
        biz_contentMap.put("bank_account_name", m.getBank_account_name());
        biz_contentMap.put("bank_account_type", m.getBank_account_type());
        biz_contentMap.put("bank_card_type", m.getBank_card_type());
        biz_contentMap.put("bank_name", m.getBank_name());
        biz_contentMap.put("bank_type", m.getBank_type());
        biz_contentMap.put("bank_province", m.getBank_province());
        biz_contentMap.put("bank_city", m.getBank_city());
        biz_contentMap.put("cert_type", m.getCert_type());
        biz_contentMap.put("cert_no", m.getCert_no());
        biz_contentMap.put("bank_telephone_no", m.getBank_telephone_no());
        biz_contentMap.put("org_no",m.getOrg_no());

        param.put("biz_content", JSON.toJSONString(biz_contentMap));

        try {
            //签名
            log.error("银盛报备入参数:{}",JSON.toJSONString(param));
            Map<String, String> sPara = buildRequestPara(param);
            log.error("完整参数{}",JSON.toJSONString(param));
            ////payLog.info("银盛商户注册接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_IMAGE_TOKEN_URL(), sPara);
            ////payLog.info("银盛商户注册接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_merchant_register_accept_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_online_h5_pay_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_merchant_register_accept_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_register_accept_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_h5_pay_response.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_online_h5_pay_response);
            }
            ////payLog.info("银盛商户注册接口验签："+verifyResult);
            resultMap.put("verifyResult", verifyResult);
            ////payLog.info("银盛商户注册接口业务返回参数："+resultMap.toString());
            log.error("银盛报备入参数：{}",JSON.toJSONString(resultMap));
            return resultMap;
        } catch (Exception e) {
            log.error("报备出错：{}",e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
            ////payLog.info("\r\n 银盛商户注册接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }

    }

    @Override
    public Map<String, Object> getYsState(Map<String, Object> rquestParams) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        ////payLog.info("商户报备注册======================");
        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //实名认证
        param.put("method", "ysepay.merchant.register.query");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());

        //业务参数（参数名biz_content,值为一个json格式对象，下面列表描述json对象的值）：
        Map<String, Object> biz_contentMap = new HashMap<String, Object>();
        String merchantNo = rquestParams.containsKey("mer_outside_custid") ? rquestParams.get("mer_outside_custid").toString() : "";
        String userCode = rquestParams.containsKey("usercode") ? rquestParams.get("usercode").toString() : "";

        biz_contentMap.put("merchant_no", merchantNo);
        biz_contentMap.put("usercode", userCode);

        param.put("biz_content", JSON.toJSONString(biz_contentMap));
        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            ////payLog.info("银盛商户注册查询接口参数："+sPara.toString());
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_IMAGE_TOKEN_URL(), sPara);
            ////payLog.info("银盛商户注册查询接口返回数据："+returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_merchant_register_query_response");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_online_h5_pay_response = (Map) JSON.parseObject(obj.toString());
                int ss = returnString.toString().indexOf("ysepay_merchant_register_query_response");
                String str = returnString.substring(ss);
                str = str.replace("ysepay_merchant_register_query_response", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_h5_pay_response.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_online_h5_pay_response);
            }
            ////payLog.info("银盛商户注册查询接口验签："+verifyResult);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            ////payLog.info("\r\n 银盛商户注册查询接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            ////payLog.info("\r\n 银盛商户注册查询接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            ////payLog.info("\r\n 银盛商户注册查询接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }

    @Override
    public String aliWap(YsPayOrderBean m) {
        Map<String, Object> resultMap = new HashMap<String, Object>();

        Map<String, String> param = new HashMap<String, String>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        param.put("method", "ysepay.online.wap.directpay.createbyuser");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr("yyyy-MM-dd HH:mm:ss"));
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
       /* param.put("notify_url", ysepayConfig.NOTIFY_ALPAY_URL);*/
        /*param.put("return_url", ysepayConfig.RETURN_ALIPAY_URL);*/
        param.put("version", ysPayDTO.getVERSION());
        param.put("out_trade_no", m.getOut_trade_no());
        param.put("shopdate", DateFormatHelper.getNowTimeStr("yyyyMMdd"));
        param.put("subject", m.getSubject());
        param.put("pay_mode", "native");
        param.put("bank_type", "1903000");
        param.put("total_amount", m.getTotal_amount() + "");
        param.put("seller_name", ysPayDTO.getSELLER_NAME());
        param.put("seller_id", ysPayDTO.getPARTNER_ID());
        param.put("timeout_express", "1h");
        param.put("business_code", "3010002");
        ////payLog.info("\r\n 银盛支付宝支付"+JSON.toJSONString(param));
        //param.put("biz_content", JSON.toJSONString(biz_contentMap));
        String returnString = "";
        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL(), sPara);
            ////payLog.info("\r\n 银盛支付宝支付返回结果"+returnString);
            return returnString;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return returnString;
        }
    }

    @Override
    public Map<String, Object> splitRequestReceipt(String bizContent) {
        Map resultMap = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        //校验json字符串
        if(StringUtils.isEmpty(bizContent)){
            return ReturnUtils.paramIsNull();
        }
        //封装参数
        Map<String, String> param = new HashMap<>();
        param.put("method", "ysepay.single.division.online.query");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());
        param.put("biz_content", bizContent);

        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            System.out.println("请求参数含有签名=" + returnString);
            sb.append("\r\n 请求参数含有签名 = " + returnString);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_single_division_online_query_response");
            Map<String, Object> ysepay_single_division_online_query_response = (Map) JSON.parseObject(obj.toString());
            ysepay_single_division_online_query_response.put("sign", resultMap.get("sign"));

            boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), obj.toString(), "utf-8");
            resultMap.putAll(ysepay_single_division_online_query_response);
            resultMap.put("verifyResult", verifyResult);
            sb.append("银盛分账查询接口验签："+verifyResult);
            return resultMap;
        } catch (IOException e) {
            ////payLog.info("\r\n 银盛分账查询接口错误："+e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            System.out.println(e1.getMessage());
            e1.printStackTrace();
            ////payLog.info("\r\n 银盛分账查询接口错误："+e1.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            ////payLog.info("\r\n 银盛分账查询接口错误："+e.getMessage());
        } finally {
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> splitReceipt(Map<String, Object> mapParams) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Object temp = mapParams.get("biz_content");
        String bizContent = temp != null ? temp.toString() : null;

        //封装公共参数
        Map<String, String> param = new HashMap<>();
        param.put("method", "ysepay.single.division.online.accept");
        param.put("partner_id", ysPayDTO.getPARTNER_ID());
        param.put("timestamp", DateFormatHelper.getNowTimeStr());
        param.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        param.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        param.put("version", ysPayDTO.getVERSION());
        param.put("notify_url", ysPayDTO.getNOTIFY_FZ_URL());
        param.put("biz_content", bizContent);
        try {
            //签名
            Map<String, String> sPara = buildRequestPara(param);
            String returnString = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sPara);
            resultMap = (Map) JSON.parse(returnString);
            Object obj = resultMap.get("ysepay_single_division_online_accept_response");
            Map<String, Object> ysepay_single_division_online_accept_response = (Map) JSON.parseObject(obj.toString());
            ysepay_single_division_online_accept_response.put("sign", resultMap.get("sign"));

            boolean verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), obj.toString(), "utf-8");
            resultMap.putAll(ysepay_single_division_online_accept_response);
            resultMap.put("verifyResult", verifyResult);
            return resultMap;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> withdrawal(Map<String, Object> mapParams) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Object temp = mapParams.get("biz_content");
        String bizContent = temp != null ? temp.toString() : null;

        //封装公共请求参数Map
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("method", "ysepay.merchant.withdraw.quick.accept");
        paramMap.put("partner_id", ysPayDTO.getPARTNER_ID());
        paramMap.put("timestamp", DateFormatHelper.getNowTimeStr());
        paramMap.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        paramMap.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        paramMap.put("version", ysPayDTO.getVERSION());
        paramMap.put("notify_url", ysPayDTO.getNOTIFY_WITHDRAWAL_URL());
        paramMap.put("biz_con", JSON.toJSONString(bizContent));

        //签名信息
        try {
            Map<String, String> sParaMap = buildRequestPara(paramMap);
            String returns = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sParaMap);
            resultMap = (Map) JSON.parse(returns);
            Object obj = resultMap.get("ysepay_merchant_withdraw_quick_accept");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_merchant_withdraw_quick_accept = (Map) JSON.parseObject(obj.toString());
                int yscount = returns.toString().indexOf("ysepay_merchant_withdraw_quick_accept");
                String str = returns.substring(yscount);
                str = str.replace("ysepay_merchant_withdraw_quick_accept", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_merchant_withdraw_quick_accept.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_merchant_withdraw_quick_accept);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> ysPay(Map<String, Object> paramMap) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        YsPayDTO ysPayDTO=ysBusinessPramService.ysBusinessPram();
        Object temp = paramMap.get("biz_content");
        String bizContent = temp != null ? temp.toString(): null;

        //封装公共请求参数Map
        Map<String, String> paramsMap = new HashMap<>();
        paramsMap.put("method", "ysepay.online.h5.pay");
        paramsMap.put("partner_id", ysPayDTO.getPARTNER_ID());
        paramsMap.put("timestamp", DateFormatHelper.getNowTimeStr());
        paramsMap.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        paramsMap.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        paramsMap.put("version", ysPayDTO.getVERSION());
        paramsMap.put("notify_url", ysPayDTO.getNOTIFY_YSPAY_URL());
        paramsMap.put("biz_con", JSON.toJSONString(bizContent));

        //签名信息
        try {
            Map<String, String> sParaMap = buildRequestPara(paramsMap);
            String returns = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sParaMap);
            resultMap = (Map) JSON.parse(returns);
            Object obj = resultMap.get("ysepay_online_h5_pay");
            boolean verifyResult = false;
            if (obj != null) {
                Map<String, Object> ysepay_online_h5_pay = (Map) JSON.parseObject(obj.toString());
                int yscount = returns.toString().indexOf("ysepay_online_h5_pay");
                String str = returns.substring(yscount);
                str = str.replace("ysepay_online_h5_pay", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_online_h5_pay.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_online_h5_pay);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } finally {
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> transferAccounts(Map<String, Object> mapParams) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Object temp = mapParams.get("biz_content");
        String bizContent = temp !=null ? temp.toString(): null;
        YsPayDTO ysPayDTO=this.ysBusinessPramService.ysBusinessPram();
        //封装公共参数以及业务参数
        Map<String, String> paramsMap = new HashMap<>();
        //加急
        paramsMap.put("method", "ysepay.df.single.quick.accept");
        paramsMap.put("partner_id", ysPayDTO.getPARTNER_ID());
        paramsMap.put("timestamp", DateFormatHelper.getNowTimeStr());
        paramsMap.put("charset", ysPayDTO.getDEFAULT_CHARSET());
        paramsMap.put("sign_type", ysPayDTO.getSIGN_ALGORITHM());
        paramsMap.put("version", ysPayDTO.getVERSION());
        paramsMap.put("notify_url", ysPayDTO.getNOTIFY_TRANSFER_URL());
        paramsMap.put("biz_con", JSON.toJSONString(bizContent));


        try {
            Map<String, String> sParaMap = buildRequestPara(paramsMap);
            String returns = Https.httpsSend(ysPayDTO.getYSEPAY_GATEWAY_URL_DSF(), sParaMap);
            resultMap = (Map) JSON.parse(returns);
            Object obj = resultMap.get("ysepay_df_single_quick_accept");
            boolean verifyResult = false;
            if(obj != null){
                Map<String, Object> ysepay_df_single_quick_accept = (Map) JSON.parseObject(obj.toString());
                int yscount = returns.toString().indexOf("ysepay_df_single_quick_accept");
                String str = returns.substring(yscount);
                str = str.replace("ysepay_df_single_quick_accept", "");
                str = str.substring(2, str.length() - 1);
                verifyResult = this.verifyJsonSign(resultMap.get("sign").toString(), str, "utf-8");
                ysepay_df_single_quick_accept.put("sign", resultMap.get("sign"));
                resultMap.putAll(ysepay_df_single_quick_accept);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return resultMap;
        }
    }



}
